# -*- coding:utf-8 -*-

import sys
from PySide6 import QtCore, QtGui, QtWidgets
from PySide6.QtCore import Qt
from PySide6.QtGui import QAction
from PySide6.QtWidgets import (QApplication, QMainWindow, QMenuBar,
                             QMenu , QPlainTextEdit)


class DemoMenu(QMainWindow):
    def __init__(self, parent=None):
        super(DemoMenu, self).__init__(parent)
        # 设置窗口标题
        self.setWindowTitle('实战PySide6: QMenu Demo-记事本')
        # 设置窗口大小
        self.resize(480, 360)

        self.initUi()

    def initUi(self):
        menuBar = self.menuBar()
        fileMenu = menuBar.addMenu('文件')
        editMenu = menuBar.addMenu('编辑')
        formatMenu = menuBar.addMenu('格式')
        helpMenu = menuBar.addMenu('帮助')

        # 文件操作部分
        fileMenu.addAction(QAction('新建', self))
        fileMenu.addAction(QAction('打开', self))
        fileMenu.addAction(QAction("保存", self))
        fileMenu.addAction(QAction('另存为', self))
        fileMenu.addSeparator()
        fileMenu.addAction(QAction('退出', self))

        # 编辑部分
        editMenu.addAction(QAction('撤销', self))
        editMenu.addAction(QAction('恢复', self))
        editMenu.addSeparator()
        editMenu.addAction(QAction('剪切', self))
        editMenu.addAction(QAction('复制', self))
        editMenu.addAction(QAction('粘贴', self))
        editMenu.addAction(QAction('删除', self))
        editMenu.addSeparator()
        editMenu.addAction(QAction('全选', self))

        # 格式设置部分
        formatMenu.addAction(QAction('自动换行', self))

        # 帮助部分
        helpMenu.addAction(QAction('关于...', self))

        # 设置一个文本编辑器作为中心小部件
        txtEdit = QPlainTextEdit(self)
        self.setCentralWidget(txtEdit)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = DemoMenu()
    window.show()
    sys.exit(app.exec())
